package com.tongjie.hotelbooking.controller.im;

import com.tongjie.hotelbooking.dto.DtoConverters;
import com.tongjie.hotelbooking.dto.ImMessageDto;
import com.tongjie.hotelbooking.http.BaseResponse;
import com.tongjie.hotelbooking.im.message.service.ImMessageService;
import com.tongjie.hotelbooking.order.enums.SearchDirection;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/im/message")
public class ImMessageController {

    @Resource
    private ImMessageService imMessageService;

    @GetMapping("/messages")
    public BaseResponse<Page<ImMessageDto>> findMessagesByMemberConversationId(@RequestParam Long memberConversationId,
                                                                               @RequestParam(required = false) Long lastId,
                                                                               @RequestParam(required = false) SearchDirection searchDirection) {
        Page<ImMessageDto> result = this.imMessageService.findMessageByMemberConversationId(memberConversationId, lastId, searchDirection)
                .map(DtoConverters::imMessageToMessageDtoConverter);
        return BaseResponse.success(result);
    }

//    @GetMapping("/messages")
//    public BaseResponse<Page<ImMessageDto>> findMessagesByConversationId(@RequestParam Long conversationId,
//                                                                         @RequestParam(required = false) Long lastId,
//                                                                         @RequestParam(required = false) SearchDirection searchDirection) {
//        Page<ImMessageDto> result = this.imMessageService.findMessageByConversationId(conversationId, lastId, searchDirection)
//                .map(DtoConverters::imMessageToMessageDtoConverter);
//        return BaseResponse.success(result);
//    }

}
